#include<vector>
#include <algorithm>
using namespace std;
class Solution {
public:
    int numRescueBoats(vector<int>& people, int limit) {
        sort(people.begin(), people.end());
        int res=0;
        int left = 0, right = people.size() - 1;
        while (left <= right) {
            if (people[right--] + people[left] <= limit)
                ++left;
            ++res;
        }
        return res;
    }
};